import Taro,{ Component } from '@tarojs/taro'
import { View, Text,Image} from '@tarojs/components'
import { AtButton} from 'taro-ui'
import './myConnp.css'
import banyuan2 from '../../img/banyuan2.png'
import banyuan3 from '../../img/banyuan3.png'
import app from '../../main';

export default class MyConnp extends Component {

  config = {
    navigationBarTitleText: '爱眼医生'
  }
  constructor () {
    super(...arguments)
    this.state = {
      //接受传过来的参数
        textinfo:{
            "id":"1",
            "title":"满100减10元",
            "desc":"",
            "coupon_type":"满减",
            "use_type":"开始日期结束日期",
            "start_time":"2019-04-01 14:26:17",
            "end_time":"2019-08-20 14:10:48",
            "days":"30",
            "scope":"全订单可用",
            "product_type":"非定向问诊",
            "full_money":"100.00",
            "discount":"10.00",
            "amount":"100",
            "created_at":"0000-00-00 00:00:00"
        },
    }
  }
  Transformation(value){
    let new_value = parseInt(value)/10
    return new_value;
  }
  goto(){
    app.navigateTo('../findDoctor/findDoctor')
  }

  getDate(){
      let me = this
      let data = {id:this.$router.params.id}
        app.get('web/coupon/get',data,function(res){
            let textinfo = res.data.result
            if(textinfo.coupon_type == "折扣"){
            textinfo.discount = me.Transformation(textinfo.discount)
            }
            me.setState({
                textinfo:textinfo
            })
        })
  }
  componentDidMount(){
      this.getDate()
  }
  render(){
      let textinfo = this.state.textinfo
    //  已使用？ 未使用？ 已过期？
      let tag = this.$router.params.status
    // 按钮禁用？
      let isdisable = (tag == "未使用") ? (false) : (true)
      return(
            <View className='box'>
                <View className='top'>
                    <View className='contentTop'>
                        <Text className='title'>{textinfo.title}</Text>
                        {textinfo.coupon_type == "满减" 
                        ? <Text className='price'>￥{textinfo.discount}</Text>
                        : <Text className='price'>{textinfo.discount}折</Text>
                        }
                        <Text className='keyong'>满{textinfo.full_money}元可用</Text>
                    </View>
                    {tag == "新到" && <View className='contentTopRight'> <Text>{tag}</Text> </View>}
                    {tag == "将到期" && <View className='contentTopRight2'> <Text>{tag}</Text> </View>}
                </View>
                <View className='image-by'>
                <Image style='height:20px;width:20px;' src={banyuan2}/>
                <Image style='height:20px;width:20px;' src={banyuan3}/>
                </View>
                <View className='content-ul'>
                        <View className="content-ul-li">
                            • 适用项目：{textinfo.scope == null ? "" : textinfo.scope}
                        </View>
                        <View className="content-ul-li">
                            • 有效期至：{textinfo.end_time == null ? '无' : textinfo.end_time}
                        </View>
                        <View className="content-ul-li">
                            • 详细说明：{textinfo.desc == null ? "" : textinfo.desc}
                        </View>
                        <View class='bottonButton'>
                            <AtButton type='primary' onClick={this.goto} disabled={isdisable}>立即使用</AtButton>
                        </View>
                </View>
            </View>
      )
  }
}
